package com.zmcn.msg.business.msg.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zmcn.msg.bean.po.Msg;
import com.zmcn.msg.bean.vo.MsgVO;
import com.zmcn.msg.business.msg.dao.msgDao;
import com.zmcn.msg.business.msg.service.msgService;
import com.zmcn.msg.fw.action.Page;

/**
 * 
 * 消息信息业务接口实现
 * 
 * @author <b>欧建东<br/>
 *         Email:oyjd@163.com</b>
 * @version 1.0
 */
@Component
@Transactional(readOnly = true)
public class msgServiceImpl implements msgService {
	private msgDao dao;

	@Autowired
	public void setDao(msgDao dao) {
		this.dao = dao;
	}

	/**
	 * 获取消息信息列表数据
	 * 
	 * @param page
	 *            页面对象
	 * @return
	 */
	public Page<MsgVO> getList(Page<MsgVO> page) {
		return dao.getList(page);
	}

	/**
	 * 根据ID获取消息信息对象信息
	 * 
	 * @param id
	 *            ID
	 * @return
	 */
	public MsgVO getMsgVO(String msgId) {
		return dao.getMsgVO(msgId);
	}

	/**
	 * 增加消息信息
	 * 
	 * @param msgId
	 *            消息ID
	 * @param batchId
	 *            消息批次ID
	 * @param content
	 *            消息内容
	 * @param user
	 *            当前用户
	 */
	@Transactional(readOnly = false)
	public void add(String msgId, String batchId, String content, String user) {
		Msg msg = new Msg();
		msg.setMsgId(msgId);
		msg.setBatchId(batchId);
		msg.setContent(content);		
		dao.create(msg);		
	}

	/**
	 * 修改消息信息
	 * 
	 * @param msgId
	 *            消息ID
	 * @param batchId
	 *            消息批次ID
	 * @param content
	 *            消息内容
	 * @param user
	 *            当前用户
	 */
	@Transactional(readOnly = false)
	public void edit(String msgId, String batchId, String content, String user) {
		Msg msg = (Msg) dao.queryById(Msg.class, msgId);
		msg.setMsgId(msgId);
		msg.setBatchId(batchId);
		msg.setContent(content);
		dao.update(msg);
	}

	/**
	 * 删除消息信息
	 * 
	 * @param ids
	 *            多个ID
	 * @param user
	 *            当前用户
	 * @return
	 */
	@Transactional(readOnly = false)
	public void remove(String[] ids, String user) {		
		dao.remove(ids, user);
	}

}
